package com.javazyw.utils.lang;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CastUtil {
	
	public static Double phraseDouble(Double value){
		if(value == null){
			return new Double(0.0);
		}else{
			return value;	
		}
	}
	
	public static boolean isNumber(String str){
		if(stringIsBlank(str)){
			return false;
		}
        Pattern pattern=Pattern.compile("[0-9]*");
        Matcher match=pattern.matcher(str);
        if(match.matches()==false){
             return false;
        }
        else{
             return true;
        }
    }
	
	public static boolean stringIsBlank(String str){
		if(str == null || "".equals(str)){
			return true;
		}else{
			return false;
		}
    }
	
	public static void main(String[] args) {
		System.err.println(isNumber(null));
	}

	public static int phraseInt(String str) {
		int rs = Integer.valueOf(str);
		return rs;
	}
	
	public static String intToStr(Integer val) {
		if(val == null){
			return "0";
		}else{
			return val.toString();
		}
	}

	public static Double strToDoblue(String str) {
		if(stringIsBlank(str)){
			return new Double(0.0);
		}else{
			return Double.valueOf(str);
		}
	}

	public static int strToInt(String str) {
		if(stringIsBlank(str)){
			return 0;
		}else{
			return Integer.valueOf(str);
		}
	}
	
	public static long strToLong(String str) {
		if(stringIsBlank(str)){
			return 0;
		}else{
			return Long.valueOf(str);
		}
	}

	public static int dealNullInt(Integer val) {
		if(val == null){
			return 0;
		}else{
			return Integer.valueOf(val);
		}
	}

	public static int douToInt(Double douVal) {
		double d = 0.0;
		int rs = 0;
		if(douVal != null){
			d = douVal;
			rs = (int)d;
		}
		return rs;
	}

	public static boolean strToBoolean(String val) {
		boolean rs = false;
		if(stringIsBlank(val)){
			return false;
		}else{
			if("true".equals(val)){
				rs = true;
			}else{
				rs = false;
			}
		}
		return rs;
	}

}
